package com.joinway.platform.bean;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.joinway.framework.bean.BaseBean;

public class ColumnField extends BaseBean implements Cloneable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * java field name
	 */
	String name;
	
	/**
	 * java type
	 */
	String type;
	
	/**
	 * domain field annatation
	 */
	String ann;
	
	/**
	 * db column name
	 */
	String column;
	
	/**
	 * db type
	 */
	String dbType;
	
	/**
	 * whether is primary key
	 */
	boolean primaryKey;
	
	/**
	 * whether it is auto increment id
	 */
	boolean idKey;
	
	/**
	 * whether it is customer id
	 */
	boolean custIdKey;

	/**
	 * log mask annotation
	 */
	String mask;
	
	/**
	 * case format when persistent to db
	 */
	String format;
	
	/**
	 * equal or like
	 */
	String condition;
	
	/**
	 * whether the input is a required on when add/edit or not 
	 */
	boolean required;
	
	@Override
	public ColumnField clone() throws CloneNotSupportedException{
		ColumnField field = new ColumnField();
		
		try{
			PropertyUtils.copyProperties(field, this);
		}catch(Exception e){
			throw new CloneNotSupportedException(e.getMessage());
		}
		
		return field;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(column).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		if (obj == this) { return true; }
		if (obj.getClass() != getClass()) {
			return false;
		}
		ColumnField rhs = (ColumnField) obj;
		return new EqualsBuilder().appendSuper(column.equalsIgnoreCase(rhs.column)).isEquals();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUname() {
		return StringUtils.capitalize(name);
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAnn() {
		return ann;
	}

	public void setAnn(String ann) {
		this.ann = ann;
	}

	public String getColumn() {
		return column;
	}

	public void setColumn(String column) {
		this.column = column;
	}

	public String getDbType() {
		return dbType;
	}

	public void setDbType(String dbType) {
		this.dbType = dbType;
	}

	public boolean isPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(boolean primaryKey) {
		this.primaryKey = primaryKey;
	}

	public boolean isIdKey() {
		return idKey;
	}

	public void setIdKey(boolean idKey) {
		this.idKey = idKey;
	}

	public boolean isCustIdKey() {
		return custIdKey;
	}

	public void setCustIdKey(boolean custIdKey) {
		this.custIdKey = custIdKey;
	}

	public String getMask() {
		return mask;
	}

	public void setMask(String mask) {
		this.mask = mask;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public boolean isRequired() {
		return required;
	}

	public void setRequired(boolean required) {
		this.required = required;
	}
}
